/**
 * 系统设置权限设置添加管理员
 */
import './index.less'
import tem from './index.html'
import $_fn from '~plugins'
class addlogCtrl {
  constructor($scope,$rootScope,http,$ui) {
  	  console.log($scope.params)
      $scope.cancel = function () {
          $rootScope.$uiDirectiveModal.close() //关闭方法
      }
  	  $scope.param1={
  	  	oid:JSON.parse($scope.params).id,
  	  	logs_type:JSON.parse($scope.params).logs_type
  	  }
  	  //返回跟踪日志弹窗
  	  $scope.operation = function (path,item) {
		console.log('111')
        var _path = path.split('@')
        let params = JSON.stringify(item)
        if(_path[0] == 'link'){
            console.log(path)
            $state.go(_path[1],{id:1,ids:2})
        }
        if(_path[0] == 'alert'){
            $ui.modal({content:"<"+_path[1]+" params="+params+"></"+_path[1]+">"})
        }
   	 }
  	  $scope.log=function(){
  	  	$scope.cancel();//关闭弹窗
  	  	console.log('跟踪日志')
  	  	$scope.param_s={
	  	  	id:JSON.parse($scope.params).id,
	  	  	logs_type:JSON.parse($scope.params).logs_type
	  	  }
  	  	$scope.operation('alert@log',$scope.param_s)//弹出添加日志弹窗
  	  }
  	//添加管理员提交
  	  $scope.tiJiao1=function(){
	  	  	if(!$scope.param1.content){
	  	  		$ui.toast({
					text:'请输入备注',
					type:'warning',
					appendTo:'.addlog'
				})
	  	  		return 
	  	  	}
  	  		http.post('insertTracelogs.do',$scope.param1,function (data) {
				if(data.errcode==1){
					$ui.toast({
						text:data.errmsg,
						type:'succeed',
						appendTo:'.addlog'
					})
					$scope.log();//返回跟踪日志弹窗
				}else{
					$ui.toast({
						text:data.errmsg,
						type:'warning',
						appendTo:'.addlog'
					})
				}
	        },function(_data){
	            console.log(_data);//报错
	      	})
  	  }
  }
}
addlogCtrl.$inject = ['$scope','$rootScope','http','$ui']
module.exports = angular.module('directive.addlog', []).directive('addlog', function() {
    return {
        template: tem,
        replace:true,
        controller: addlogCtrl,
        scope:{
        	params:"@"
        }
    }
}).name